package com.kukudexin;

/**
 * @author: 德鑫
 * @description: 测试jdk14 的新特性里面友好的空指针异常
 * @since: 2021/4/29
 */
public class TestJdk1402 {
    public static void main(String[] args) {
        //先创建一个汽车类
        Car car = new Car();
        car.engine.power = 10;
        	/*
			早期的JDK运行后提示空指针异常:Exception in thread "main" java.lang.NullPointerException
	at com.kukudexin.TestJdk1402.main(TestJdk1402.java:12)
			无法确定是car为空还是engine为空
			在JDK14版本中,开启参数 -XX:+ShowCodeDetailsInExceptionMessages可以更好的指定哪个地方出现异常
			执行:java -XX:+ShowCodeDetailsInExceptionMessages TestJdk1402 运行程序后
			提示的空指针异常信息:Exception in thread "main" java.lang.NullPointerException: Cannot assign field "power" because "car.engine" is null
	at com.kukudexin.TestJdk1402.main(TestJdk1402.java:12)
			*/
        System.out.println("Hello World!");
    }
}

//定义发动机类
class Engine{
    int power;		//功率
    double displacment;		//排量
}

//定义小汽车类
class Car {
    String brand;	//品牌
    Engine  engine;		//发动机
}
